<?php
require_once(dirname(__FILE__)."/../../libs/dbclass/dbconnect.php");
require_once(dirname(__FILE__)."/../../libs/string/libstr.php");
require_once(dirname(__FILE__)."/../../admin/libs/power_class.php");
$mc=new libstr();
$pw=new power();
$cataid=0;
if($_GET["id"]!=""){
$cataid=$_GET["id"];
}
$mid=$_GET["mid"]?$_GET["mid"]:0;
$parr=array();
$power=$db->ds("select * from power_class where ID=".$mid."");
if($mc->Ismp($power[0]["quanxian"])!=""){
	$parr=explode(",",$power[0]["caidan"]);
}
function getchild($pid){
	global $db;
	global $mc;
	global $parr;
	$child=$db->ds("select ID from menu_class where pid=".$pid);
	for($i=0;$i<count($child);$i++){
		if(in_array($child[$i]["ID"],$parr)){
		return true;	
		}
	}
	return false;
}
//print_r($parr);
header("Content-Type:text/xml;");
echo '<?xml version="1.0" encoding="utf-8"'.'?'.'>';
echo '<tree id="0">';
echo '<item text="'.$power[0]["classname"].'的菜单" id="-1" open="1" call="1" select="1" >';
echo getclass(0);
function getclass($cataid=0){
	
	global $db;
	global $mc;
	global $parr;
	 $sql="select ID,classname,rootid,(select count(b.ID) as tt from menu_class as b where b.pid=t.ID) as tj from menu_class as t where t.pid=".$cataid."  ";
	 $getrs=$db->ds($sql);
	 if(count($getrs)>0){
		for($i=0;$i<count($getrs);$i++){
			if($getrs[$i]["tj"]==0){	
				if(in_array($getrs[$i][ID],$parr)){
					echo '<item text="'.$getrs[$i][classname].'" id="'.$getrs[$i][ID].'"  child="'.$getrs[$i]["tj"].'" checked="1" >';	
				}else{
					echo '<item text="'.$getrs[$i][classname].'" id="'.$getrs[$i][ID].'"  child="'.$getrs[$i]["tj"].'" >';	
				}
			}else{
				//nocheckbox代表是否显示选择框
				 if(getchild($getrs[$i][ID])=='true'){
					echo '<item text="'.$getrs[$i][classname].'" id="'.$getrs[$i][ID].'"  child="'.$getrs[$i]["tj"].'"  open="1">';	//子集被选中就展开，open代表展开
				 }else{
					 echo '<item text="'.$getrs[$i][classname].'" id="'.$getrs[$i][ID].'"  child="'.$getrs[$i]["tj"].'"  >';			
				 }
			}
			getclass($getrs[$i][ID]);
		}
	 }
 echo '</item>';
}
echo '</tree>';
?>